import 'package:flutter/material.dart';

class NavigationIconView{

    NavigationIconView({
      Key key,
      Widget icon,
      Widget activeIcon,
      String title,
      }): _icon = icon,
          _activeIcon = activeIcon,
          _title = title,
          item = new BottomNavigationBarItem(
            icon: icon,
            activeIcon: activeIcon,
            title: new Text(title),
          );
 
    final Widget _icon;
    final Widget _activeIcon;
    final String _title;
    final BottomNavigationBarItem item;

}

class MainScreen extends StatefulWidget {
  @override
  _MainScreenState createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {

  int _currentIndex = 0;
  List<NavigationIconView> _navgationIconViews;
 

 @override
   void initState() {
     // TODO: implement initState
     super.initState();
     _navgationIconViews = <NavigationIconView>[
      new NavigationIconView(
        icon: new Icon(Icons.chat),
        activeIcon: new Icon(Icons.chat_bubble),
        title: "微信",
      ),
      new NavigationIconView(
        icon: new Icon(Icons.perm_contact_calendar),
        activeIcon: new Icon(Icons.content_paste),
        title: "通讯录",
      ),
      new NavigationIconView(
        icon: new Icon(Icons.find_in_page),
        activeIcon: new Icon(Icons.search),
        title: "发现",
      ),
      new NavigationIconView(
        icon: new Icon(Icons.person),
        activeIcon: new Icon(Icons.person),
        title: "我",
      ),

     ];
   }
 
  @override
  Widget build(BuildContext context) {
    final BottomNavigationBar botNavBar = new BottomNavigationBar(
      items: _navgationIconViews.map<BottomNavigationBarItem>((NavigationIconView navigationIconview){
        return navigationIconview.item;
      }).toList(),
      currentIndex: _currentIndex,
      type: BottomNavigationBarType.fixed,
      onTap: (int index){
        print("点击了 $index tab项目");
      },
    );
    return Scaffold(
      appBar: new AppBar(
        title: new Text("微信"),

      ),

      body: new Container(

        color: Colors.green,

      ),

      bottomNavigationBar: botNavBar,

    );
  }
}